package com.gac.basedownload

import android.os.AsyncTask
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.gac.basedownload.model.DownloadConfig
import com.yanzhenjie.permission.AndPermission
import com.yanzhenjie.permission.Permission

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        DownloadConfig.context = this
        //requestPermissions()
        AndPermission.with(this).permission(Permission.WRITE_EXTERNAL_STORAGE,Permission.READ_EXTERNAL_STORAGE).onGranted {
            var task = object :AsyncTask<String,String,String>(){

                override fun doInBackground(vararg params: String?): String {
                    Log.e("gacmy","startDownload")
                    var download = GacDownload.Builder().url("http://121.40.139.174:8092/down/panel/apk/1583910938033.jpg").build()
                    download.startDownload()
                    return ""
                }

            }
            task.execute()
        }.start()

    }

    override fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<out String>,
        grantResults: IntArray
    ) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
    }
}
